<!--
默认为应用首页，应该是员工打开的页面
-->
<template>
	<div class="worker-wrap">

		<!--<h1 class="c-red">员工工作台</h1>-->
		<!--
		<div>isLoginUser:{{ isLoginUser }}</div>
		<div>token:{{ token }}</div>
		<div>登录用户信息{{ userInfo }}</div>
		<div>
			<el-button type="primary" @click="login">手动登录</el-button>
			&lt;!&ndash;<el-button type="primary" @click="setToken">设置token</el-button>&ndash;&gt;
			<el-button type="primary" @click="setUserinfo">设置用户信息</el-button>
		</div>
		-->

		<div class="coupon-wrap">
			<div class="item" v-for="item in dataListOfCoupon" :key="item.id">
				<div class="stockName">{{item.stockName}}</div>
				<div class="stockId">卡券号：{{item.stockId}}</div>
				<div class="condition">满{{item.transactionMinimum}}减{{item.discountAmount}}</div>
				<div>开始时间：{{item.availableBeginTime}}</div>
				<div>结束时间：{{item.availableEndTime}}</div>
				<div>
					<el-button type="success" @click="couponGet(item)">查看优惠券详情</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>

import mixins from "@/mixins/mixins";
import mixinsWx from "@/mixins/mixinsWx";
import { apiCouponListOfBusiness } from "@/axios/api";

export default {
    nane:"worker",
	mixins: [mixins,mixinsWx],
    components: {},
    data() {
        return {

			//////////////////////////复杂数据//////////////////
			dataListOfCoupon:[],//优惠券列表
        }
	},
	computed:{},
	created(){
		//开发判断
		if(this.dev == true){
			console.log('dev模式，直接读取券列表')
			this.getCoupongList();
		}else{
			console.log('生产模式，调用init()')
			this.init()
		}

	},
    mounted(){},
	methods:{

		/**
		 * 初始化
		 */
    	init(){
			//关于这里的判断如果是外部客户进入了本页，也会执行这个逻辑，但不会跳转到这个页面
		    if(this.isLoginUser){
				this.notify('你已经登录，将读取数据','success')
			    this.getCoupongList();
		    }else{
			    this.login()
		    }
	    },

		/**
		 * 拼接url，跳转到微信地址 ，找微信获取code，
		 */
		login (){
			let url = this.getRedirectUrlWorkder() // 得到跳转url
			console.log('准备进行登录跳转...')
			Swal.fire({
				// position:'top',
				html: '正在进行登录跳转，请稍候...',
				// type: "success",
				// showConfirmButton: true,
				timer:10000,
				backdrop:true,//遮罩
				allowOutsideClick: false,//允许外部点击关闭
				onBeforeOpen: () => { Swal.showLoading() },
				onAfterClose: () => {console.log("关闭")}
			});

			setTimeout(() => {
				window.location.href = url
			},2000)
			// if(!this.isLoginUser){//员工没有登录，就进行登录
			//
			// }else{
			// 	this.notify('当前员工已经登录','success')
			// }

		},

		/**
		 * 获取券列表
		 */
		getCoupongList() {
			apiCouponListOfBusiness().then((res)=>{
				if(res.resultFlag == true){
					this.dataListOfCoupon = [...res.data]
				}else{
					this.$message.error(res.resultMsg)
				}
			})
		},

		//复制分享链接
		copyCouponUrl(item) {

		},

		//去领券页面，测试的
		couponGet(item) {
			let _couponId = item.stockId
			let _userId = this.userId //store里的
			console.log(_couponId,_userId)
			this.$router.push({
				path:'/couponGet',
				query:{
					couponId:_couponId,
					userId:_userId
				}
			})
		},

		/////////////////////////////////////其它////////////////////////////////////////
		/////////////////////////////////////其它////////////////////////////////////////
		/////////////////////////////////////其它////////////////////////////////////////
		setToken() {
			// this['userWork/SET_TOKEN']('jwttoken1231231231313')
			this.$store.commit('userWork/SET_TOKEN','eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.UQmqAUhUrpDVV2ST7mZKyLTomVfg7sYkEjmdDI5XF8Q')
		},

		setUserinfo() {
			let _data =  {errcode: 0, UserId: "YangZhiCong", DeviceId: "18f486f1-a677-4e69-9154-3f0c3605f034", errmsg: "ok"}
			// this['userWork/SET_USERINFO'](_data)
			this.$store.commit('userWork/SET_USERINFO',_data)
		},
		sweetAlert(){
			Swal.fire({
				position:'top',
				html: '正在登录，请稍候...',
				// type: "success",
				// showConfirmButton: true,
				backdrop:true,//遮罩
				allowOutsideClick: false,
				onBeforeOpen: () => { Swal.showLoading() },
				onAfterClose: () => {
					console.log("关闭")
				}
			});
		}
	}
}
</script>


<style lang="less" scoped>
.worker-wrap{
	word-break:break-all;
	* {word-break:break-all;}
}

.coupon-wrap{
	.item{
		max-width: 400px;
		color:#fff;
		background-color: #ff9887;
		border-radius:5px;
		padding:10px;
		box-shadow: 3px 3px 3px rgba(100,100,100,0.2);
		.stockName{color:rgba(255,255,255,0.8);font-size: 18px;font-weight: bold;border-bottom:1px solid rgba(255,255,255,0.3)}
		.stockId{}
		.condition{}
	}
}

</style>
